package com.baosight.sczx.zm.cf.service;

import java.util.HashMap;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.common.zm.cInterface.User;
import com.baosight.sczx.zm.cf.domain.ZMCFAuthoritySelect;

public class ServiceZMCF30 extends ServiceEPBase {

	/**
	 * 初始化方法
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCF30</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-10-19上午01:39:44 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		this.check();
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(User.getInstance().getConstructionStaff("cmes.cf.empName", "empCode", "empName", true));//人员
		return outInfo;
	}

	/**
	 * 查询方法
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCF30</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-10-19上午01:39:50 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {
		String fdFeedbackpersonId = UserSession.getUserId() == null ? "" : UserSession.getUserId().toString();//登陆人ID
		StaticTools.setQueryParameters(inInfo, "fdFeedbackpersonId", fdFeedbackpersonId, true);//添加查询条件
		
		EiInfo outInfo = super.query(inInfo, "ZMCFAuthoritySelect.query", new ZMCFAuthoritySelect());
		return outInfo;
	}
	
	/**
	 * 反馈新增
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCF30</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-10-19上午03:05:25 严洪浩
	 * </p>
	 *
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) {
		String fdKeyId = TablePk.getInstance().getNextValue("T_CF_AUTHORITY_FEEDBACK");//反馈记录ID
		
		inInfo.getBlock("result").setCell(0, "fdKeyId", fdKeyId);
		inInfo.getBlock("result").setCell(0, "fdTime", StaticTools.getDateTime());
		inInfo.getBlock("result").setCell(0, "fdFeedbackperson", UserSession.getInSessionProperty("UserCname"));
		super.update(inInfo, "ZMCFAuthorityFeedback.feedback");//主表反馈
		EiInfo outInfo = super.update(inInfo, "ZMCFAuthorityFeedback.insert");//从表新增
		return outInfo;
	}
	
	/**
	 * 查收
	 * <p>Function: check</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-10-19上午03:14:29 严洪浩
	 * </p>
	 *
	 */
	private int check() {
		String fdFeedbackpersonId = UserSession.getUserId() == null ? "" : UserSession.getUserId().toString();//登陆人ID
		Map<String, String> _args = new HashMap<String, String>();
		_args.put("fdFeedbackpersonId", fdFeedbackpersonId);
		int count = dao.update("ZMCFAuthorityFeedback.check", _args);
		
		return count;
	}
}
